home *** CD-ROM | disk | FTP | other *** search
- Path: titan.fullerton.edu!grosin
- From: grosin@titan.fullerton.edu (Gil Rosin)
- Newsgroups: comp.lang.c++
- Subject: Help a newbie with 2 simple questions...
- Date: 24 Feb 1996 22:24:36 GMT
- Organization: California State University at Fullerton
- Message-ID: <4go374$619@wintermute.ecs.fullerton.edu>
- NNTP-Posting-Host: titan.ecs.fullerton.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hi, I've just started playing around with C++ so these are basic questions. I'm
- using Borland C++ v3.1, so this might not be applicable to the c++ general
- group, but I am not too familiar with C++, so I'll ask anyways :)
-
- 1) is there any formatting available with cout? other then cout.width()? A book
- I have says it is acceptable to mix a ANSI C and C++ for stuff like sprintf
- and the like to do formatted output??
-
- 2) I've begun to play around with reference variables and reference functions.
- What are REAL world uses for it? I've come up with the following:
- a) If I pass an integer to a function and want to be able to modify it, I
- have to use pointers, that means asterisks and ambersands all over the
- place, but with referecing, I only need one ambersand, it doesn't seem
- like a must, just a convience.
- b) reference functions
-
- Ok, make it 3, question on reference functions, what can I do with them? An
- example in the book shows something like this:
-
- int Array[10];
-
- int &Test(int Index);
-
- main()
- {
- Test(2) = 45;
- return 0;
- }
-
- int &Test(int Index)
- {
- return Array[Index];
- }
-
- in this example, Array[2] is assigned 45, all nice and cool, but is this all
- I can do with it?
-
- I tried to do my own example with a simple struct:
-
- typedef struct
- {
- char Name[40];
- int ID;
- } Student;
-
- Student Std[20];
-
- Student &Student(int Index);
-
- main()
- {
- sprintf(Std[1].Name, "Test");
- Std[1].ID = 20;
-
- Student(10) = Std[1];
- return 0;
- }
-
- Student &StudentInit(int Index)
- {
- return Std[Index];
- }
-
- Sorry, had a few typos in there, obvious the "Student" function has too be
- called something else, but anyways, the only use I could find for something
- like this is to copy one record to another position. Is this all I could
- do with it? I thought perhaps I could say something like:
-
- StudentInit(20) = "Test", 19;
-
- or something like that to initiaize the record, the above line probably doesn't
- make sense now that I Think about it, but just something of that basic idea.
-
- Please reply via email to grosin@titan.fullerton.edu
-
- Thanks.
-
-
-